package com.neusoft.Shixun.controller;

import com.neusoft.Shixun.po.CareRecord;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.CareRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin("*")
@RequestMapping("/CareRecordController")
public class CareRecordController {

    @Autowired
    private CareRecordService careRecordService;

    @GetMapping
    public ResponseBean<List<CareRecord>> getAllCareRecords() {
        return careRecordService.getAllCareRecords();
    }

    @GetMapping("/{id}")
    public ResponseBean<CareRecord> getCareRecordById(@PathVariable Integer id) {
        return careRecordService.getCareRecordById(id);
    }

    @GetMapping("/getCareRecordByClientId")
//    根据客户id查询护理记录
    public ResponseBean<List<CareRecord>> getCareRecordByClientId(@RequestParam Integer id) {
        return careRecordService.getCareRecordByClientId(id);
    }

    @GetMapping("/getCareRecordByCareTakerId")
//    健康管家查询自己客户的护理记录,可以根据姓名模糊查询
    public ResponseBean<List<CareRecord>> getCareRecordByCareTakerId(@RequestParam Integer careTakerId, @RequestParam(required = false) String clientName) {
        return careRecordService.getCareRecordByCareTakerId(careTakerId, clientName);
    }

    @PostMapping("/addCareRecord")
//    添加护理记录，同时更新客户护理项目数量
    public ResponseBean<Integer> addCareRecord(@RequestBody CareRecord careRecord) {
        return careRecordService.addCareRecord(careRecord);
    }

    @PutMapping("/{id}")
    public ResponseBean<Integer> updateCareRecord(@PathVariable Integer id, @RequestBody CareRecord careRecord) {
        careRecord.setRecordId(id);
        return careRecordService.updateCareRecord(careRecord);
    }

    @DeleteMapping("/deleteCareRecord")
//    护理记录逻辑删除
    public ResponseBean<Integer> deleteCareRecord(@RequestParam Integer id) {
        return careRecordService.deleteCareRecord(id);
    }
}